#include "BBN.h"


int main(int argc, char* argv[])
{
    Screen screen(800, 600);
    if(screen.failed())
    {
        print_line("Failed to initialize.");
        return 1;
    }
    
    Color color[4] = {Color(128, 128, 128), Color(128, 128, 128), Color(128, 128, 128), Color(128, 128, 128)};
    float x[4] = {200, 600, 200, 600};
    float y[4] = {150, 150, 450, 450};
    
    Input input;
    bool done = false;
    while(!done)
    {
        while(input.next_event())
        {
            if(input.is_quit() || input.key_pressed(SDL_SCANCODE_ESCAPE))
                done = true;
            else if(input.is_gamepad_event())
            {
                for(int i = 0; i < 4; i++)
                {
                    if(input.gamepads[i].button1.pressed())
                        color[i] = Color(255, 0, 0);
                    else if(input.gamepads[i].button2.pressed())
                        color[i] = Color(0, 255, 0);
                    else if(input.gamepads[i].button3.pressed())
                        color[i] = Color(0, 0, 255);
                    else if(input.gamepads[i].button4.pressed())
                        color[i] = Color(255, 0, 255);
                    else if(input.gamepads[i].button1.released())
                        color[i] = Color(128, 128, 128);
                    else if(input.gamepads[i].button2.released())
                        color[i] = Color(128, 128, 128);
                    else if(input.gamepads[i].button3.released())
                        color[i] = Color(128, 128, 128);
                    else if(input.gamepads[i].button4.released())
                        color[i] = Color(128, 128, 128);
                }
            }
        }
        
        for(int i = 0; i < 4; i++)
        {
            x[i] += -input.gamepads[i].joystick1.value_left() + input.gamepads[i].joystick1.value_right();
            y[i] += -input.gamepads[i].joystick1.value_up() + input.gamepads[i].joystick1.value_down();
            x[i] += -input.gamepads[i].joystick2.value_left() + input.gamepads[i].joystick2.value_right();
            y[i] += -input.gamepads[i].joystick2.value_up() + input.gamepads[i].joystick2.value_down();
            x[i] += -input.gamepads[i].joystick3.value_left() + input.gamepads[i].joystick3.value_right();
            y[i] += -input.gamepads[i].joystick3.value_up() + input.gamepads[i].joystick3.value_down();
        }
        
        screen.clear();
        
        for(int i = 0; i < 4; i++)
        {
            screen.fill(Circle(x[i], y[i], 40), color[i]);
        }
        
        screen.show();
        
        wait(0.01f);
    }
    
	return 0;
}

